1205A - Almost Equal - CodeForces Solution


constructive algorithms greedy math *1200

Please click on ads to support us..

Python Code:

from collections import deque,defaultdict
import sys
def inp(): return int(sys.stdin.readline())
def mpp(): return map(int,sys.stdin.readline().rstrip().split())
def lis(): return list(map(int,sys.stdin.readline().rstrip().split()))

def main():
    n=inp()
    if n%2:
        arr=[0]*(2*n)
        for i in range(n):
            if i%2:
                arr[i]=2*i+1
                arr[i+n]=arr[i]+1
            else:
                arr[i]=2*i+2
                arr[i+n]=arr[i]-1
        sys.stdout.write("YES\n")
        for i in arr:
            sys.stdout.write(str(i)+" ")
    else:
        sys.stdout.write("NO")
    
if __name__=="__main__":
    main()

C++ Code:

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
 
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
 
 
ll Count_digit(ll N)
{
    ll Count = 0;
    while(N > 0)
    {
        Count++;
        N = N / 10;
    }
    return Count;
}
 
 
int Mod(ll N)
{
    return N % 1000000007;
}
bool isprime(ll N)
{
    if(N == 1)
        return false;
    for(ll i = 2; i*i <= N; i++)
        if(N % i == 0)
            return false;
    return true;
}
bool cmp(ll a, ll b)
{
    return a>b;
}
ll power(ll a,ll b)
{
    ll temp=1;
    while(b--)
        temp*=a;
    return temp;
}

ll stringToInt(const string &s)
{
    stringstream om(s);
    ll num=-1;
    om>>num;
    return num;
}

string intToString(ll n)
{
    ostringstream ostr;
    ostr<<n;
    return ostr.str();
}

void PrintVf(vector<ll> Arr)
{
    for(int i = 0; i < Arr.size(); i++)
        cout <<Arr[i] <<" ";
    cout << endl;
}


void PrintVb(vector<ll> Arr)
{
    for(int i = Arr.size() - 1; i >= 0; i--)
        cout <<Arr[i] <<" ";
    cout << endl;
}

ll binpow(ll a, ll b)
{
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
 
void solve()
{
    ll N;
    cin >> N;
    if(N % 2 == 0)
        NO
    else
    {
        YES
        for(int i = 0; i < N; i++)
        {
            if(i % 2 == 0)
                cout << 2 * i + 1 << " ";
            else
                cout << 2 * i + 2 << " ";
        }
        for(int i = 0; i < N; i++)
        {
            if(i % 2 == 0)
                cout << 2 * i + 2 << " ";
            else
                cout << 2 * i + 1 << " ";
        }
    }
    cout << endl;


}
 
 
int main()
{
 
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

1697C - awoo's Favorite Problem
165A - Supercentral Point
1493A - Anti-knapsack
1493B - Planet Lapituletti
747B - Mammoth's Genome Decoding
1591C - Minimize Distance
1182B - Plus from Picture
1674B - Dictionary
1426C - Increase and Copy
520C - DNA Alignment
767A - Snacktower
1365A - Matrix Game
714B - Filya and Homework
31A - Worms Evolution
1691A - Beat The Odds
433B - Kuriyama Mirai's Stones
892A - Greed
32A - Reconnaissance
1236D - Alice and the Doll
1207B - Square Filling
1676D - X-Sum
1679A - AvtoBus
1549A - Gregor and Cryptography
918C - The Monster
4B - Before an Exam
545B - Equidistant String
1244C - The Football Season
1696B - NIT Destroys the Universe
1674A - Number Transformation
1244E - Minimizing Difference